﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Operator_ContractsList : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Operator"))
        {
            Response.Redirect("~/Account/Login.aspx");
        }
        else
        {
            SqlDataSourceContracts.SelectParameters["OperatorId"].DefaultValue = getOperatorId().ToString();
        }
    }

    protected int getOperatorId()
    {
        var operators = from bankOperator in db.Operators where bankOperator.UserId == (Guid)Membership.GetUser().ProviderUserKey select bankOperator;
        return operators.First().OperatorId;
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string contractId = GridView1.DataKeys[GridView1.SelectedIndex]["ContractId"].ToString();
        var contracts = from contract in db.Contracts where contract.ContractId == Convert.ToInt32(contractId) select contract;
        Session.Add("contractId", contractId);
        Response.Redirect("~/Operator/ContractInformation.aspx");
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void GridView1_DataBinding(object sender, EventArgs e)
    {
        SqlDataSourceContracts.SelectParameters["OperatorId"].DefaultValue = getOperatorId().ToString();
    }
}